<template>
  <div class="list-container">
    <h4 class="title item">加班记录</h4>
    <div v-for="item in data" :key="item.id" @click="showAction(item)" class="item">
      <div class="time-wrap">
        <strong class="big-title">{{item.overtime_date | week}}</strong>
        <div class="sub">{{item.overtime_date.substr(0, 10)}}</div>
      </div>
      <div class="flex1">
        <div class="remark text-ellipsis-mul">{{item.type}}</div>
      </div>
      <div class="record">
        <strong class="big-title">{{item.overtime_salary}}元</strong>
        <div class="sub">{{item.overtime}}个小时</div>
      </div>
      <div class="arrow-box"></div>
    </div>

    <mt-actionsheet :actions="actions" v-model="visbile">
    </mt-actionsheet>
  </div>
</template>

<script>
export default {
  props: {
    data: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      record: {},
      visbile: false,
      actions: [
        { name: '编辑', method: this.toEdit },
        { name: '删除', method: this.remove }
      ]
    }
  },
  methods: {
    showAction(record) {
      this.record = record
      this.visbile = true
    },
    async remove() {
      const { id } = this.record
      await this.$http({
        url: '/api/overtime/record',
        params: { id },
        method: 'delete'
      })
      this.$emit('refresh')
    },
    toEdit() {
      const { id } = this.record
      this.$router.push({ name: 'overtimeEdit', query: { id } })
    }
  }
}
</script>

<style lang="scss" scoped>
.list-container {
  border-top: 0.3rem solid #f5f5f5;
  .item {
    min-height: 1rem;
    display: flex;
    align-items: center;
    padding: 0 0.4rem;
    border-bottom: 1px solid #eee;
    & > div {
      display: flex;
      align-items: center;
      justify-items: center;
      flex-direction: column;
    }
  }
  .title {
    padding: 0 0.2rem;
  }
  .big-title {
    font-size: 0.28rem;
  }
  .sub {
    font-size: 0.26rem;
    color: 999;
    padding-top: 0.1rem;
  }
  .remark {
    font-size: 0.3rem;
    max-height: 0.96rem;
    word-break: break-all;
    white-space: pre-wrap;
    line-height: 1.5;
    padding: 0 0.2rem;
  }
  .record {
    min-width: 100px;
  }
}
</style>
